package com.changli04.date;

import org.junit.Test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateTest {
    @Test
    public void test() {
        Date date = new Date();
        //获取当前时间
        System.out.println(date.toString()); //Wed Dec 25 17:30:48 CST 2024
        // 获取当前 时间戳
        System.out.println(date.getTime()); //1735118789487

        Date date2 = new Date(1335118789487L);
        System.out.println(date2.toString());
    }
    @Test
    public void test2() {
        java.sql.Date date = new java.sql.Date(1335118789487L);
        System.out.println(date.toString());  //2012-04-23
        System.out.println(date.getTime());
    }
    @Test
    public void test3() {
        SimpleDateFormat sdf = new SimpleDateFormat();//"yyyy-MM-dd"     default
        System.out.println(sdf.format(new Date()));//2024-12-25          2024/12/25 17:35
        Date date = null;
        try {
             date = sdf.parse("2024/12/25 17:35");
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
        System.out.println(date);
    }
}
